#include <string.h>
#include <stdio.h>

#include "utils/enumFactory.h"

/**
 * 运行状态:
 * SUCCESS 成功
 * IDLE	空闲
 * BUSY	负载
 * RUNNING	运行中
 * FAILED	失败
 * TIMEOUT	超时
 */

/** !!! 下面几行宏定义会产生下面的一行代码 */
// enum RunState { SUCCESS = 0, IDLE , BUSY , RUNNING , FAILED , TIMEOUT = 10, }; const char *GetRunStateString(RunState dummy); RunState GetRunStateValue(const char *string); const char *GetRunStateString(RunState value) { switch (value) { case SUCCESS: return "SUCCESS"; case IDLE: return "IDLE"; case BUSY: return "BUSY"; case RUNNING: return "RUNNING"; case FAILED: return "FAILED"; case TIMEOUT: return "TIMEOUT"; default: return ""; } } RunState GetRunStateValue(const char *str) { if (!strcmp(str, "SUCCESS")) return SUCCESS; if (!strcmp(str, "IDLE")) return IDLE; if (!strcmp(str, "BUSY")) return BUSY; if (!strcmp(str, "RUNNING")) return RUNNING; if (!strcmp(str, "FAILED")) return FAILED; if (!strcmp(str, "TIMEOUT")) return TIMEOUT; return (RunState)0; }

#define RUNSTATE(XX) \
    XX(SUCCESS, = 0) \
    XX(IDLE, )       \
    XX(BUSY, )       \
    XX(RUNNING, )    \
    XX(FAILED, )     \
    XX(TIMEOUT, = 10)

DEFINE_ENUM(RunState, RUNSTATE)

int main(int argc, char const *argv[])
{
    printf("%s: %d\n", GetRunStateString(IDLE), GetRunStateValue("IDLE"));
    return 0;
}
